package ihm.panel.site;

import java.awt.GridLayout;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import javax.swing.JDialog;
import javax.swing.JLabel;

/**
 * @see http://stackoverflow.com/questions/8336161
 * @see http://stackoverflow.com/questions/6163606
 */
public class JDialogWait extends Thread {
	
	private JDialog wait_jd;
	private String message;
	
	public JDialogWait(String message) {
		this.message = message;
	}
	
	@Override
	public void run() {
		initDialog();
	}

	public void initDialog() {
		wait_jd = new JDialog();
		wait_jd.setLayout(new GridLayout(0, 1));
		wait_jd.add(new JLabel(message, JLabel.CENTER));

		wait_jd.addWindowListener(new WindowAdapter() {
			@Override
			public void windowClosing(WindowEvent e) {
				System.out.println(e.paramString());
			}
		});
	}

	public void display() {
		wait_jd.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
		wait_jd.pack();
		wait_jd.setLocationRelativeTo(null);
		wait_jd.setVisible(true);
	}

	public void close() {
		wait_jd.setVisible(false);
		wait_jd.dispose();
	}

}
